package com.apes.fn.fico.reimbursement.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 赋能费用类型明细
 * @author cyy
 * @create 2023.3.28
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name= FeeTypeExpenseItem.CONST_TABLE_NAME)
public class FeeTypeExpenseItem extends BaseModel {
    public static final String CONST_TABLE_NAME = "fn_fee_type_expense_item";

    @Id
    @Column(name = "id", nullable = false, length = 120)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "编码", padding = 8)
    @Comment("编码")
    private String id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "fee_type_expense_id", referencedColumnName = "id")
    @Comment("费用借支")
    private FeeTypeExpense feeTypeExpense;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id")
    @Comment("部门")
    private Dept dept;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fee_type_id", referencedColumnName = "id")
    @Comment("费用事项")
    private FeeType feeType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "expense_type_id", referencedColumnName = "id")
    @Comment("费用类型")
    private Enumeration expenseType;

    @Column(name = "amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("费用金额")
    private double amount= 0;

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "occurrence_date")
    @Comment("费用发生日期")
    private Date occurrenceDate;

    @Column(name = "remark")
    @Comment("摘要")
    private String remark;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reimburser_id", referencedColumnName = "id")
    @Comment("报销人")
    private PartyRole reimburserId;
}
